﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TPLOAWebService.Models
{
    public class ClinicRepository : IClinicRepository
    {
        public IEnumerable<Clinic> GetAll()
        {
            return TPLOADBManager.GetAllClinic().Cast<Clinic>();
        }

        public Clinic Get(string id)
        {
            return TPLOADBManager.GetClinicByID(id);
        }

        public Clinic Add(Clinic item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (TPLOADBManager.InsertClinic(item) == 0)
            {
                return null;
            }
            else
            {
                return item;
            }
        }

        public void Remove(string id)
        {
            TPLOADBManager.DeleteClinic(id);
        }

        public bool Update(Clinic item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (TPLOADBManager.UpdateClinic(item) == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}